package databasetranslation;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import models.Client;
import database.SQLServer;

public class ClientList extends DatabaseList<Client>{
	
	/**
	 * Creates a ClientList
	 * 
	 * @param server for the database communication
	 */
	public ClientList(SQLServer server) {
		super(server, "clientlist");
	}
	
	/**
	 * Returns a List of all the clients
	 * 
	 * @return List<Client>
	 */
	public List<Client> getClients() {
		return new ArrayList<Client>(getEntries());
	}
	
	/**
	 * Look for similar clients.
	 * 
	 * @param other Client to compare with
	 * @return clients that are similar
	 */
	public List<Client> getSimilarClients(Client other) {
		List<Client> similar = new ArrayList<Client>();
		for (Client client : getClients()) {
			if (other != client && other.isSimilarTo(client)) {
				similar.add(client);
			}
		}
		return similar;
	}

	/**
	 * Create a Client from the current selected ResultSet row
	 * 
	 * @param rs ResultSet with a selected row of a Payment
	 * @return the Client created from the ResultSet
	 */
	@Override
	public Client convertResultSetToModel(ResultSet rs) throws SQLException {
		return new Client(rs.getInt("id"),rs.getString("givenname"),rs.getString("lastname"),rs.getString("address"),rs.getString("phone"),rs.getString("email"));
	}
}